package action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import entitybean.l_sequence.EntityBeanL_Sequence;
import entitybean.oc_date_sur.EnitityBeanOc_Date_Sur;
import entitybean.oc_boat.EntityBeanOc_Boat;
import entitybean.oc_boat_ben.EntityBeanOc_Boat_Ben;
import entitybean.oc_boat_ice.EntityBeanOc_Boat_Ice;
import entitybean.oc_boat_pla.EntityBeanOc_Boat_Pla;
import entitybean.oc_depthlist.EntityBeanOc_Depthlist;
import entitybean.oc_property.EntityBean_Oc_Property;
import entitybean.oc_property_tools.EntityBean_Oc_Property_Tools;
import entitybean.oc_station.EntityBeanOc_Station;
import entitybean.oc_voyage.EnitityBeanOc_Voyage;
import form.DataForm;

import service.service_admin.Service_Admin;
import service.service_public.Service_Public;
import tools.InterfaceForResultSetToList;
import tools.PageBeanPlus;
import view.ViewOc_Data;


public class Action_Oc_Date_Sur extends DispatchAction {
	private Service_Admin service_admin;
	private Service_Public service_public;

	public Service_Admin getService_admin() {
		return service_admin;
	}

	public void setService_admin(Service_Admin serviceAdmin) {
		service_admin = serviceAdmin;
	}

	public Service_Public getService_public() {
		return service_public;
	}

	public void setService_public(Service_Public servicePublic) {
		service_public = servicePublic;
	}

	public ActionForward admin_init_oc_date_sur_import(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		System.out.println("海洋数据导入页面");
		List<EntityBeanOc_Boat>list=this.service_admin.Find_Oc_Boat_By_oc_boatkind_Active();
		request.setAttribute("list",list);
		return mapping.findForward("success");
	}
	public ActionForward admin_init_oc_date_ben_import(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		System.out.println("海洋数据导入页面");
		List<EntityBeanOc_Boat_Ben>list=this.service_admin.Find_Oc_Boat_Ben_By_oc_boatkind_Active();
		request.setAttribute("list",list);
		return mapping.findForward("success");
	}
	public ActionForward admin_init_oc_date_pla_import(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		System.out.println("海洋数据导入页面");
		List<EntityBeanOc_Boat_Pla>list=this.service_admin.Find_Oc_Boat_Pla_By_oc_boatkind_Active();
		request.setAttribute("list",list);
		return mapping.findForward("success");
	}
	public ActionForward admin_init_oc_date_ice_import(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		System.out.println("海洋数据导入页面");
		List<EntityBeanOc_Boat_Ice>list=this.service_admin.Find_Oc_Boat_Ice_By_oc_boatkind_Active();
		request.setAttribute("list",list);
		return mapping.findForward("success");
	}
	
	

	public ActionForward admin_init_oc_date_sur(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		System.out.println("海洋数据查询页面");
		DataForm dataform = (DataForm) form;
		String sql = "select ID,VALUE_KEY,"
				+ "(SELECT OC_DEPTHLIST.DEPTH FROM OC_DEPTHLIST WHERE OC_DEPLIST_ID=OC_DEPTHLIST.ID)OC_DEPLIST_ID,"
				+ "(SELECT OC_STATION.STATION_NAME FROM OC_STATION WHERE OC_STATION_ID=OC_STATION.ID)OC_STATION_ID,"
				+ "(SELECT OC_VOYAGE.VOYAGE_NAME FROM OC_VOYAGE WHERE OC_VOYAGE_ID=OC_VOYAGE.ID)OC_VOYAGE_ID,"
				+ "(SELECT OC_PROPERTY.PROPERTY_NAME FROM OC_PROPERTY WHERE OC_PROPERTY_ID=OC_PROPERTY.ID)OC_PROPERTY_ID,"
				+ "(SELECT OC_PROPERTY_TOOLS.TOOLS_NAME FROM OC_PROPERTY_TOOLS WHERE OC_PROPERTY_TOOLS_ID=OC_PROPERTY_TOOLS.ID)OC_PROPERTY_TOOLS_ID,"
				+ "(SELECT OC_BOAT.OC_BOATNAME FROM OC_BOAT WHERE (SELECT OC_VOYAGE.BOATID FROM OC_VOYAGE WHERE ID=OC_VOYAGE_ID)=OC_BOAT.ID)OC_BOAT_ID"
				+ " FROM OC_DATE_SUR where DEL='OFF' ORDER BY ID";
		System.out.println("SQL=" + sql);
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(dataform.getRowcountperpage()), Integer
						.valueOf(dataform.getCurrentpage()), "loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Data> list = interfaceforresultsettolist
				.ViewOc_Data(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("dataform", dataform);
		System.out.println("list.size()" + list.size());

		return mapping.findForward("success");
	}

	public ActionForward admin_load_oc_date_sur(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		DataForm dataform = (DataForm) form;
		System.out.println("载入的序列号的值="+dataform.getId());
		
		String id=dataform.getId();
		
		EnitityBeanOc_Date_Sur e=this.service_admin.Find_EnitityBeanOc_Date_Sur(Integer.valueOf(id));
		System.out.println(e.Read_Me());
		
		
		List<EntityBeanOc_Boat>boat_list=this.service_admin.Find_Oc_Boat_By_oc_boatkind_Active();
		List<EntityBean_Oc_Property>property_list=this.service_admin.Find_EntityBean_Oc_Property_by_property_kind(5);
		List<EntityBeanOc_Depthlist>depthlist= this.service_admin.Find_Oc_Depthlist();
		Integer boat_id=
		this.service_admin.Find_Oc_Voyage_By_id(e.getOc_voyage_id().toString()).getBoatid();//船只的数据
		List<EnitityBeanOc_Voyage> voyage_list=this.service_admin.Find_Oc_Voyage_By_boatid(boat_id);
		List<EntityBeanOc_Station>station_list=this.service_admin.Find_Oc_Station_by_oc_voyage_id(e.getOc_voyage_id());
		List<EntityBean_Oc_Property_Tools> property_tool_list=this.service_admin.Find_EntityBean_Oc_Property_Tools_by_property_id(e.getOc_property_id());
		
		
		request.setAttribute("voyage_list",voyage_list);
		request.setAttribute("station_list",station_list);
		request.setAttribute("property_tool_list",property_tool_list);
		request.setAttribute("depthlist",depthlist);
		request.setAttribute("boat_list",boat_list);
		request.setAttribute("property_list",property_list);
		request.setAttribute("boat_id", boat_id);
		request.setAttribute("e",e);
		
		
		return mapping.findForward("success");
	}

	public ActionForward admin_add_oc_date_sur(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		System.out.println("准备添加一个海洋环境科考船信息");
		DataForm dataform = (DataForm) form;
		List<EntityBeanOc_Boat>boat_list=this.service_admin.Find_Oc_Boat_By_oc_boatkind_Active();
		List<EntityBean_Oc_Property>property_list=this.service_admin.Find_EntityBean_Oc_Property_by_property_kind(5);
		List<EntityBeanOc_Depthlist>depthlist= this.service_admin.Find_Oc_Depthlist();
		
		
		request.setAttribute("depthlist",depthlist);
		request.setAttribute("boat_list",boat_list);
		request.setAttribute("property_list",property_list);
		return mapping.findForward("success");
	}

	public ActionForward admin_insert_oc_date_sur(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DataForm dataform = (DataForm) form;
		Integer	Oc_property_id= dataform.getOc_property_id();
		Integer Oc_property_tools_id= dataform.getOc_property_tools_id();
		Integer Oc_station_id= dataform.getOc_station_id();
		Integer Oc_voyage_id =dataform.getOc_voyage_id();
		Double Value_key= dataform.getValue_key();
		Integer oc_deplist_id =dataform.getOc_deplist_id();
		
		
		EnitityBeanOc_Date_Sur e=new EnitityBeanOc_Date_Sur();
		e.setDel("OFF");
		e.setOc_xls_upload(0);

		EntityBeanL_Sequence l=this.service_public.Find_L_Sequence_By_seq_Name("SEQ_OC_DATE_SUR");
		Integer id=l.getSeq_Value()+1;
		l.setSeq_Value(id);
		e.setId(id);
		e.setOc_deplist_id(oc_deplist_id);
		e.setOc_property_id(Oc_property_id);
		e.setOc_property_tools_id(Oc_property_tools_id);
		e.setOc_station_id(Oc_station_id);
		e.setOc_voyage_id(Oc_voyage_id);
		e.setValue_key(Value_key);
		
		this.service_public.Update_L_Sequence(l);
		this.service_admin.Insert_Oc_Data_Sur(e);
		
		
		
		String sql = "select ID,VALUE_KEY,"
			+ "(SELECT OC_DEPTHLIST.DEPTH FROM OC_DEPTHLIST WHERE OC_DEPLIST_ID=OC_DEPTHLIST.ID)OC_DEPLIST_ID,"
			+ "(SELECT OC_STATION.STATION_NAME FROM OC_STATION WHERE OC_STATION_ID=OC_STATION.ID)OC_STATION_ID,"
			+ "(SELECT OC_VOYAGE.VOYAGE_NAME FROM OC_VOYAGE WHERE OC_VOYAGE_ID=OC_VOYAGE.ID)OC_VOYAGE_ID,"
			+ "(SELECT OC_PROPERTY.PROPERTY_NAME FROM OC_PROPERTY WHERE OC_PROPERTY_ID=OC_PROPERTY.ID)OC_PROPERTY_ID,"
			+ "(SELECT OC_PROPERTY_TOOLS.TOOLS_NAME FROM OC_PROPERTY_TOOLS WHERE OC_PROPERTY_TOOLS_ID=OC_PROPERTY_TOOLS.ID)OC_PROPERTY_TOOLS_ID,"
			+ "(SELECT OC_BOAT.OC_BOATNAME FROM OC_BOAT WHERE (SELECT OC_VOYAGE.BOATID FROM OC_VOYAGE WHERE ID=OC_VOYAGE_ID)=OC_BOAT.ID)OC_BOAT_ID"
			+ " FROM OC_DATE_SUR where DEL='OFF' ORDER BY ID";
	System.out.println("SQL=" + sql);
	PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
			Integer.valueOf(dataform.getRowcountperpage()), Integer
					.valueOf(dataform.getCurrentpage()), "loadrichtext()");
	InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
	List<ViewOc_Data> list = interfaceforresultsettolist
			.ViewOc_Data(pagebeanplus.getFormatqueryresultset());

	request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
	request.setAttribute("list", list);
	request.setAttribute("dataform", dataform);
	System.out.println("list.size()" + list.size());
		
		return mapping.findForward("success");
	}

	public ActionForward admin_delete_oc_date_sur(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		System.out.println("删除海洋环境层深");
		DataForm dataform = (DataForm) form;
		String id = dataform.getId();
		id = this.cut_tail(id);
		
		System.out.println("id="+id);
		this.service_admin.Delete_Oc_Data_Sur(id);

		String sql = "select ID,VALUE_KEY,"
				+ "(SELECT OC_DEPTHLIST.DEPTH FROM OC_DEPTHLIST WHERE OC_DEPLIST_ID=OC_DEPTHLIST.ID)OC_DEPLIST_ID,"
				+ "(SELECT OC_STATION.STATION_NAME FROM OC_STATION WHERE OC_STATION_ID=OC_STATION.ID)OC_STATION_ID,"
				+ "(SELECT OC_VOYAGE.VOYAGE_NAME FROM OC_VOYAGE WHERE OC_VOYAGE_ID=OC_VOYAGE.ID)OC_VOYAGE_ID,"
				+ "(SELECT OC_PROPERTY.PROPERTY_NAME FROM OC_PROPERTY WHERE OC_PROPERTY_ID=OC_PROPERTY.ID)OC_PROPERTY_ID,"
				+ "(SELECT OC_PROPERTY_TOOLS.TOOLS_NAME FROM OC_PROPERTY_TOOLS WHERE OC_PROPERTY_TOOLS_ID=OC_PROPERTY_TOOLS.ID)OC_PROPERTY_TOOLS_ID,"
				+ "(SELECT OC_BOAT.OC_BOATNAME FROM OC_BOAT WHERE (SELECT OC_VOYAGE.BOATID FROM OC_VOYAGE WHERE ID=OC_VOYAGE_ID)=OC_BOAT.ID)OC_BOAT_ID"
				+ " FROM OC_DATE_SUR where DEL='OFF' ORDER BY ID";
		System.out.println("SQL=" + sql);
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(dataform.getRowcountperpage()), Integer
						.valueOf(dataform.getCurrentpage()), "loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Data> list = interfaceforresultsettolist
				.ViewOc_Data(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("dataform", dataform);
		System.out.println("list.size()" + list.size());

		return mapping.findForward("success");

	}

	public ActionForward admin_update_oc_date_sur(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		DataForm dataform = (DataForm) form;
		String id=dataform.getId();
		EnitityBeanOc_Date_Sur e=new EnitityBeanOc_Date_Sur();
		e=this.service_admin.Find_EnitityBeanOc_Date_Sur(Integer.valueOf(id));
		Integer	Oc_property_id= dataform.getOc_property_id();
		Integer Oc_property_tools_id= dataform.getOc_property_tools_id();
		Integer Oc_station_id= dataform.getOc_station_id();
		Integer Oc_voyage_id =dataform.getOc_voyage_id();
		Double Value_key= dataform.getValue_key();
		Integer oc_deplist_id =dataform.getOc_deplist_id();
		e.setOc_deplist_id(oc_deplist_id);
		e.setOc_property_id(Oc_property_id);
		e.setOc_property_tools_id(Oc_property_tools_id);
		e.setOc_station_id(Oc_station_id);
		e.setOc_voyage_id(Oc_voyage_id);
		e.setValue_key(Value_key);
		this.service_admin.Update_Oc_Data_Sur(e);
		
		String sql = "select ID,VALUE_KEY,"
			+ "(SELECT OC_DEPTHLIST.DEPTH FROM OC_DEPTHLIST WHERE OC_DEPLIST_ID=OC_DEPTHLIST.ID)OC_DEPLIST_ID,"
			+ "(SELECT OC_STATION.STATION_NAME FROM OC_STATION WHERE OC_STATION_ID=OC_STATION.ID)OC_STATION_ID,"
			+ "(SELECT OC_VOYAGE.VOYAGE_NAME FROM OC_VOYAGE WHERE OC_VOYAGE_ID=OC_VOYAGE.ID)OC_VOYAGE_ID,"
			+ "(SELECT OC_PROPERTY.PROPERTY_NAME FROM OC_PROPERTY WHERE OC_PROPERTY_ID=OC_PROPERTY.ID)OC_PROPERTY_ID,"
			+ "(SELECT OC_PROPERTY_TOOLS.TOOLS_NAME FROM OC_PROPERTY_TOOLS WHERE OC_PROPERTY_TOOLS_ID=OC_PROPERTY_TOOLS.ID)OC_PROPERTY_TOOLS_ID,"
			+ "(SELECT OC_BOAT.OC_BOATNAME FROM OC_BOAT WHERE (SELECT OC_VOYAGE.BOATID FROM OC_VOYAGE WHERE ID=OC_VOYAGE_ID)=OC_BOAT.ID)OC_BOAT_ID"
			+ " FROM OC_DATE_SUR where DEL='OFF' ORDER BY ID";
	System.out.println("SQL=" + sql);
	PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
			Integer.valueOf(dataform.getRowcountperpage()), Integer
					.valueOf(dataform.getCurrentpage()), "loadrichtext()");
	InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
	List<ViewOc_Data> list = interfaceforresultsettolist
			.ViewOc_Data(pagebeanplus.getFormatqueryresultset());

	request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
	request.setAttribute("list", list);
	request.setAttribute("dataform", dataform);
	System.out.println("list.size()" + list.size());

		
		
		
		
		return mapping.findForward("success");
	}

	public ActionForward admin_search_oc_date_sur(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		System.out.println("海洋数据查询页面");
		DataForm dataform = (DataForm) form;
		String sql = "select ID,VALUE_KEY,"
				+ "(SELECT OC_DEPTHLIST.DEPTH FROM OC_DEPTHLIST WHERE OC_DEPLIST_ID=OC_DEPTHLIST.ID)OC_DEPLIST_ID,"
				+ "(SELECT OC_STATION.STATION_NAME FROM OC_STATION WHERE OC_STATION_ID=OC_STATION.ID)OC_STATION_ID,"
				+ "(SELECT OC_VOYAGE.VOYAGE_NAME FROM OC_VOYAGE WHERE OC_VOYAGE_ID=OC_VOYAGE.ID)OC_VOYAGE_ID,"
				+ "(SELECT OC_PROPERTY.PROPERTY_NAME FROM OC_PROPERTY WHERE OC_PROPERTY_ID=OC_PROPERTY.ID)OC_PROPERTY_ID,"
				+ "(SELECT OC_PROPERTY_TOOLS.TOOLS_NAME FROM OC_PROPERTY_TOOLS WHERE OC_PROPERTY_TOOLS_ID=OC_PROPERTY_TOOLS.ID)OC_PROPERTY_TOOLS_ID,"
				+ "(SELECT OC_BOAT.OC_BOATNAME FROM OC_BOAT WHERE (SELECT OC_VOYAGE.BOATID FROM OC_VOYAGE WHERE ID=OC_VOYAGE_ID)=OC_BOAT.ID)OC_BOAT_ID"
				+ " FROM OC_DATE_SUR where DEL='OFF' ORDER BY ID";
		System.out.println("SQL=" + sql);
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(dataform.getRowcountperpage()), Integer
						.valueOf(dataform.getCurrentpage()), "loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Data> list = interfaceforresultsettolist
				.ViewOc_Data(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("dataform", dataform);
		System.out.println("list.size()" + list.size());

		return mapping.findForward("success");
	}

	private String cut_tail(String str) {
		String cut = str;
		if (str.endsWith(",")) {
			cut = cut.substring(0, cut.length() - 1);
		}
		return cut;
	}
}
